<template>
  <div class="child1">
    <h2>我是Child1组件 —— 我弟弟很好，给了我一个玩具:{{toy}}</h2>
  </div>
</template>

<script>
  export default {
    name:'Child1',
    data() {
      return {
        toy:''
      }
    },
    methods:{
      getToy(value){
        console.log('我是哥哥，send-toy事件被触发了，所以getToy调用了',value)
        this.toy = value
      }
    },
    mounted(){
      this.$bus.$on('send-toy',this.getToy)
    },
    beforeDestroy(){
      this.$bus.$off('send-toy')
    },
  }
</script>

<style scoped>
  .child1 {
    background-color: skyblue;
    padding: 10px;
  }
</style>